package com.ss.android.article.base.ui;

import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.ss.android.article.common.e.SubEntrance;

import java.util.ArrayList;
import java.util.List;

public class SingleLineLinerLayout extends LinearLayout {
    List<SubEntrance> a;
    Context b;
    private long c;
    private List<List<View>> d;
    private LayoutInflater e;
    private List<Integer> f;
    private int g;

    public SingleLineLinerLayout(Context arg2) {
        super(arg2);
        this.d = new ArrayList();
        this.f = new ArrayList();
        this.b = arg2;
        this.a();
    }

    public SingleLineLinerLayout(Context arg2, AttributeSet arg3) {
        super(arg2, arg3);
        this.d = new ArrayList();
        this.f = new ArrayList();
        this.b = arg2;
        this.a();
    }

    public SingleLineLinerLayout(Context arg2, AttributeSet arg3, int arg4) {
        super(arg2, arg3, arg4);
        this.d = new ArrayList();
        this.f = new ArrayList();
        this.b = arg2;
        this.a();
    }

    private void a() {
        this.e = LayoutInflater.from(this.getContext());
    }

    static long a(SingleLineLinerLayout arg2) {
        return arg2.c;
    }

    static long a(SingleLineLinerLayout arg1, long arg2) {
        arg1.c = arg2;
        return arg2;
    }

    public int getDisplayNumbers() {
        return this.g;
    }

    protected void onLayout(boolean arg18, int arg19, int arg20, int arg21, int arg22) {
        int v1_3;
        ArrayList v1_1;
        int v10;
        int v9;
        this.d.clear();
        this.f.clear();
        this.g = 0;
        int row = this.getWidth();
        int v4 = this.getPaddingLeft();
        int v3 = this.getPaddingTop();
        ArrayList v2 = new ArrayList();
        int v7 = this.getChildCount();
        int v5 = v4;
        v4 = v3;
        v3 = 0;
        while (true) {
            if (v3 < v7) {
                View v8 = this.getChildAt(v3);
                ViewGroup.LayoutParams v1 = v8.getLayoutParams();
                v9 = v8.getMeasuredWidth();
                v10 = v8.getMeasuredHeight();
                if (((ViewGroup.MarginLayoutParams) v1).leftMargin + v9 + ((ViewGroup.MarginLayoutParams) v1).rightMargin + this.getPaddingRight() + v5 > row) {
                    this.f.add(Integer.valueOf(v4));
                    this.d.add(v2);
                    if (this.g == 0) {
                        this.g = ((List) v2).size();
                    }
                    v1_1 = new ArrayList();
                } else {
                    v5 += v9 + ((ViewGroup.MarginLayoutParams) v1).leftMargin + ((ViewGroup.MarginLayoutParams) v1).rightMargin;
                    v4 = Math.max(v4, ((ViewGroup.MarginLayoutParams) v1).bottomMargin + (((ViewGroup.MarginLayoutParams) v1).topMargin + v10));
                    ((List) v2).add(v8);
                    ++v3;
                    continue;
                }
            } else {
                v1_1 = v2;
                break;
            }

            break;
        }

        this.f.add(Integer.valueOf(v4));
        this.d.add(v1_1);
        if (this.g == 0) {
            this.g = this.d.get(0).size();
        }

        v4 = this.getPaddingLeft();
        int v2_1 = this.getPaddingTop();
        int v8_1 = this.d.size();
        row = 0;
        for (v7 = v2_1; row < v8_1; v7 += v9) {
            Object v3_1 = this.d.get(row);
            v9 = this.f.get(row).intValue();
            Log.e("SingleLineLinerLayout", "第" + row + "行 ：" + ((List) v3_1).size() + " , " + v3_1);
            Log.e("SingleLineLinerLayout", "第" + row + "行， ：" + v9);
            v5 = 0;
            while (v5 < ((List) v3_1).size()) {
                Object v1_2 = ((List) v3_1).get(v5);
                if (((View) v1_2).getVisibility() != GONE) {
                    ViewGroup.LayoutParams v2_2 = ((View) v1_2).getLayoutParams();
                    v10 = ((ViewGroup.MarginLayoutParams) v2_2).leftMargin + v4;
                    int v11 = ((ViewGroup.MarginLayoutParams) v2_2).topMargin + v7;
                    int v12 = ((View) v1_2).getMeasuredWidth() + v10;
                    int v13 = ((View) v1_2).getMeasuredHeight() + v11;
                    Log.e("SingleLineLinerLayout", v1_2 + " , l = " + v10 + " , t = " + arg20 + " , r =" + v12 + " , b = " + v13);
                    ((View) v1_2).layout(v10, v11, v12, v13);
                    v1_3 = ((View) v1_2).getMeasuredWidth() + ((ViewGroup.MarginLayoutParams) v2_2).rightMargin + ((ViewGroup.MarginLayoutParams) v2_2).leftMargin + v4;
                } else {
                    v1_3 = v4;
                }

                ++v5;
                v4 = v1_3;
            }

            v4 = this.getPaddingLeft();
            ++row;
        }
    }

    protected void onMeasure(int arg18, int arg19) {
        int v3_1;
        super.onMeasure(arg18, arg19);
        int v7 = View.MeasureSpec.getSize(arg18);
        int v6 = View.MeasureSpec.getSize(arg19);
        int v11 = View.MeasureSpec.getMode(arg18);
        int v12 = View.MeasureSpec.getMode(arg19);
        int v5 = this.getPaddingLeft() + this.getPaddingRight();
        int v4 = this.getPaddingBottom() + this.getPaddingTop();
        int v13 = this.getChildCount();
        int v10 = v5;
        v5 = 0;
        int v9 = v4;
        v4 = 0;
        int v8 = 0;
        while (true) {
            if (v8 < v13) {
                View v14 = this.getChildAt(v8);
                this.measureChild(v14, arg18, arg19);
                ViewGroup.LayoutParams v3 = v14.getLayoutParams();
                int v15 = v14.getMeasuredWidth() + ((ViewGroup.MarginLayoutParams) v3).leftMargin + ((ViewGroup.MarginLayoutParams) v3).rightMargin;
                v3_1 = ((ViewGroup.MarginLayoutParams) v3).bottomMargin + (v14.getMeasuredHeight() + ((ViewGroup.MarginLayoutParams) v3).topMargin);
                if (v10 + v15 > v7) {
                    v3_1 = v4 + v9;
                    v4 = Math.max(v10, v15);
                } else {
                    v10 += v15;
                    v9 = Math.max(v9, v3_1);
                    if (v8 == v13 - 1) {
                        v3_1 = v4 + v9;
                        v4 = Math.max(v5, v10);
                    } else {
                        v3_1 = v4;
                        v4 = v5;
                    }

                    ++v8;
                    v5 = v4;
                    v4 = v3_1;
                    continue;
                }
            } else {
                v3_1 = v4;
                v4 = v5;
                break;
            }

            break;
        }
        if (v11 == 1073741824) {
            v4 = v7;
        }

        if (v12 == 1073741824) {
            v3_1 = v6;
        }

        this.setMeasuredDimension(v4, v3_1);
    }

    public void setCategoryName(String arg1) {
    }

    public void setData(List arg5) {
        this.a = arg5;
        this.removeAllViews();
        if (this.a != null && this.a.size() != 0) {
            int v2;
            for (v2 = 0; v2 < this.a.size(); ++v2) {
                String v1 = this.a.get(v2).name;
                String v0 = this.a.get(v2).openUrl;
                if (v1 != null && !android.support.design.a.isTextEmpty(v1) && v0 != null && !android.support.design.a.isTextEmpty(v0)) {
                    View v3 = this.e.inflate(com.ss.android.article.browser.R.layout.ij, null);
                    View v0_1 = v3.findViewById(com.ss.android.article.browser.R.id.ab5);
                    ((TextView) v0_1).setText(this.a.get(v2).name);
                    ((TextView) v0_1).setTag(this.a.get(v2).openUrl);
                    ((TextView) v0_1).setOnClickListener(new an(this, v2));
                    this.addView(v3);
                }
            }
        }
    }
}

